package com.tscnd.core.dao;



import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.tscnd.core.entity.User;

@Mapper
public interface UserMapper {
	
	@Select("SELECT * FROM USER WHERE NAME = #{name}")
    User findByName(@Param("name") String name);
	
	/**
	 * 直接以单个字段做为传参
	 * @param name
	 * @param age
	 * @return
	 */
    @Insert("INSERT INTO USER(NAME, AGE) VALUES(#{name}, #{age})")
    int insert(@Param("name") String name, @Param("age") Integer age);
    
    /**
     * 以map方式进行传参
     * @param map
     * @return
     */
    @Insert("INSERT INTO USER(NAME, AGE) VALUES(#{name,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER})")
    int insertByMap(Map<String, Object> map);
    

    /**
     * 以对象的方式进行传参
     * @param user
     * @return
     */
	@Insert("INSERT INTO USER(NAME, AGE) VALUES(#{name}, #{age})")
	int insertByUser(User user);
	
	/**
	 * 修改
	 * @param user
	 */
	@Update("UPDATE USER SET AGE=#{age} WHERE NAME=#{name}")
	void update(User user);
    
	/**
	 * 删除对象
	 * @param id
	 */
	@Delete("DELETE FROM USER  WHERE ID = #{id}")
	void delete(Long id);
	
	
	@Results({
	    @Result(property = "name", column = "name"),
	    @Result(property = "age", column = "age")
	})
	@Select("SELECT name, age FROM user")
	List<User> findAll();
	
}
